/*
 * Copyright (C) 2008 Matt Falkoski
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.falko.android.raven.renderer;

import javax.microedition.khronos.opengles.GL10;
import javax.microedition.khronos.opengles.GL11Ext;

/**
 * Sprite2D
 * 
 * Simple 2D sprite class. Adapted from the GLSprite class in
 * com.android.spritemethodtest
 * 
 * Original code at http://code.google.com/p/apps-for-android/
 */
public class Sprite2D {

	// Position.
	public float x_;
	public float y_;
	public float z_;

	// Velocity.
	public float velocityX_;
	public float velocityY_;
	public float velocityZ_;

	// draw dimensions
	public float height_;
	public float width_;

	public boolean visible_;
	public Texture texture_;

	public Sprite2D() {
		texture_ = new Texture();
		reset();
	}

	public void reset() {
		visible_ = false;
		height_ = width_ = x_ = y_ = z_ = 0;
		velocityX_ = velocityY_ = velocityZ_ = 0;
		texture_ = null;
	}

	public void draw(GL10 gl) {

		if (texture_ == null || !texture_.loaded) {
			return;
		}

		if (height_ <= 0)
			height_ = texture_.height;

		if (width_ <= 0)
			width_ = texture_.width;

		gl.glBindTexture(GL10.GL_TEXTURE_2D, texture_.name);
		((GL11Ext) gl).glDrawTexfOES(x_, y_, z_, width_, height_);

	}

}
